package com.aspose.cells.a.d.a;

import com.aspose.cells.a.d.a.a.zab;
import com.aspose.cells.a.d.a.a.zac;
import com.aspose.cells.a.d.a.a.zae;
import com.aspose.cells.a.d.a.a.zaf;
import com.aspose.cells.a.d.a.a.zai;
import com.aspose.cells.a.d.a.a.zaj;
import com.aspose.cells.a.d.a.a.zaq;
import com.aspose.cells.a.d.a.a.zat;
import com.aspose.cells.a.d.a.a.zbq;
import com.aspose.cells.a.d.a.a.zbs;
import com.aspose.cells.a.d.a.a.zbv;
import com.aspose.cells.a.d.a.a.zbw;
import com.aspose.cells.a.d.a.a.zca;
import com.aspose.cells.a.d.a.a.zcc;
import com.aspose.cells.a.d.a.a.zcg;
import com.aspose.cells.a.d.a.a.zci;
import com.aspose.cells.a.d.a.a.zcj;
import com.aspose.cells.a.d.a.a.zck;
import com.aspose.cells.a.d.a.a.zcl;
import com.aspose.cells.a.d.a.a.zcm;
import com.aspose.cells.a.d.a.a.zcr;
import com.aspose.cells.a.d.a.a.zcs;
import com.aspose.cells.a.d.a.a.zcu;
import com.aspose.cells.a.d.a.a.zcx;
import com.aspose.cells.a.d.a.a.zu;
import com.aspose.cells.a.d.a.a.zx;
import com.aspose.cells.a.d.a.b.zaa;
import com.aspose.cells.a.d.a.b.zn;
import com.aspose.cells.a.d.a.b.zp;
import com.aspose.cells.a.d.a.b.zq;
import com.aspose.cells.a.d.a.b.zr;
import com.aspose.cells.a.d.a.b.zs;
import com.aspose.cells.a.d.a.b.zt;
import com.aspose.cells.a.d.a.b.zv;
import com.aspose.cells.a.d.a.b.zw;
import com.aspose.cells.a.d.a.b.zy;
import com.aspose.cells.a.d.a.b.zz;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Paint;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.TexturePaint;
import java.awt.font.TextAttribute;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D.Float;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;
import javax.imageio.ImageIO;

public class zj {
   private final zk a;
   private int b = 1;
   private zh c = null;
   private ByteArrayOutputStream d = null;
   private zd e;
   private Rectangle f;
   private Dimension g;
   private Dimension h;
   private zf i;
   private zs[] j;
   private int k = 0;
   private int l = 0;
   private zaa m;
   private int n = 0;
   private boolean o = false;
   private int p = -1;

   public zj(Rectangle var1, Dimension var2, Dimension var3, zk var4) {
      this.d = new ByteArrayOutputStream();
      this.c = new zh(this.d, this.b);
      this.e = new zd();
      this.a = var4;
      this.f = var1;
      this.g = var2;
      this.h = var3;
      this.i = new zf(this, this.c, var1);
      if (var4.a) {
         this.j = new zs[8];
         this.m = new zaa(this.j, 0);
         this.j[0] = new com.aspose.cells.a.d.a.b.zh();
         this.m.a(1);
         this.c.a(this.m);
      }

   }

   public zc a() {
      zc var1 = new zc(this, this.f);
      return var1;
   }

   public void a(OutputStream var1) throws IOException {
      this.g();
      if (this.a.a) {
         this.b((zs)(new com.aspose.cells.a.d.a.b.zf()));
      }

      this.c.a(new zx());
      byte[] var2 = this.d.toByteArray();
      int var3 = var2.length;
      int var4 = this.c.g();
      ByteArrayOutputStream var5 = new ByteArrayOutputStream();
      zb var6 = new zb(var5, true);
      ++var4;
      ze var7 = new ze(this.f, this.b, 0, var3, var4, this.e.c(), this.g, this.h);
      var7.a(var6);
      var1.write(var5.toByteArray());
      var1.write(var2);
      var1.flush();
   }

   public void a(int var1) {
      this.c.a(new zcc(var1));
   }

   public void b(int var1) {
      this.c.a(new zcj(var1));
   }

   public void c(int var1) {
      this.c.a(new zck(var1));
   }

   public void d(int var1) {
      this.c.a(new zcl(var1));
   }

   public void a(Color var1) {
      this.c.a(new zcm(var1));
   }

   public void e(int var1) {
      this.c.a(new zci(var1));
   }

   public void a(Rectangle var1, int var2, int var3) {
      if (this.a.a) {
         this.b((zs)(new com.aspose.cells.a.d.a.b.zd(var3, var2)));
         this.c.a(new zcu(var1));
         this.d();
      } else {
         this.c.a(new zcu(var1));
      }

   }

   public void b(Rectangle var1, int var2, int var3) {
      if (this.a.a) {
         this.b((zs)(new com.aspose.cells.a.d.a.b.zg(var3, var2)));
         this.c.a(new zaj(var1));
         this.d();
      } else {
         this.c.a(new zaj(var1));
      }

   }

   public void a(Rectangle var1, int var2, float var3, float var4, zcx var5, Color var6, int var7) {
      if (this.a.a) {
         if (this.p < 0) {
            this.p = this.e.a() - 1;
            this.a((zs)(new zq(this.p)));
         }

         this.b((zs)(new com.aspose.cells.a.d.a.b.ze(var6, var7 - 1, this.p, var5.a(), var1)));
         this.c.a(new zai(var1, var2, var3, var4, var5));
         this.d();
      } else {
         this.c.a(new zai(var1, var2, var3, var4, var5));
      }

   }

   public void f(int var1) {
      this.c.a(new zca(var1));
   }

   protected void a(RenderedImage var1, Color var2) {
      BufferedImage var3 = (BufferedImage)var1;
      float var4 = this.a((double)var1.getWidth());
      float var5 = this.a((double)var1.getHeight());
      zcs var6 = new zcs(this.f, 0, (int)var5, (int)var4, -((int)var5), var3, var2);
      if (this.a.a) {
         byte[] var7 = null;

         try {
            ByteArrayOutputStream var8 = new ByteArrayOutputStream();
            ImageIO.write(var1, "PNG", var8);
            var7 = var8.toByteArray();
         } catch (Exception var9) {
            com.aspose.cells.a.c.zl.b(var9);
         }

         if (var7 != null) {
            this.b((zs)(new zn(this.e.c() - 1, new com.aspose.cells.a.d.a.b.zj(var7))));
            Float var10 = new Float(0.0F, 0.0F, var4, var5);
            this.b((zs)(new com.aspose.cells.a.d.a.b.zc(this.e.c() - 1, new Float(0.0F, 0.0F, (float)var1.getWidth(), (float)var1.getHeight()), var10)));
            this.c.a(var6);
            this.d();
         } else {
            this.c.a(var6);
         }
      } else {
         this.c.a(var6);
      }

   }

   public void a(AffineTransform var1, int var2) {
      if (this.a.a) {
         switch(var2) {
         case 2:
            this.a((zs)(new zy(var1, true)));
            break;
         case 3:
            this.a((zs)(new zy(var1, false)));
         }
      }

      this.c.a(new zat(var1, var2));
   }

   public void a(AffineTransform var1) {
      if (this.a.a) {
         this.a((zs)(new zz(var1)));
      }

      this.c.a(new zcr(var1));
   }

   public void g(int var1) {
      this.c.a(new zbw(var1));
   }

   public void h(int var1) {
      this.c.a(new zu(var1));
      this.e.a(var1);
   }

   public void b() {
      if (this.a.a) {
         this.a((zs)(new com.aspose.cells.a.d.a.b.zu(this.n)));
         ++this.n;
      }

      this.c.a(new zbs());
   }

   public void c() {
      if (this.a.a) {
         --this.n;
         this.a((zs)(new zt(this.n)));
      }

      this.c.a(new zbq());
   }

   public void a(zs var1) {
      switch(var1.b()) {
      case 16392:
         if (this.k == 7) {
            this.f();
         }

         if (((com.aspose.cells.a.d.a.b.zk)var1).a() == 3) {
            this.o = true;
         }
         break;
      case 16414:
      case 16426:
         if (this.k > 0) {
            if (var1.b() == this.j[this.k - 1].b()) {
               this.j[this.k - 1] = var1;
               return;
            }

            if (this.k == 7) {
               this.f();
            }
         }
         break;
      default:
         if (this.k == 7) {
            this.f();
         }
      }

      this.j[this.k] = var1;
      ++this.k;
      this.l += var1.c();
      if (this.l > 8192) {
         this.f();
      }

   }

   private void f() {
      this.m.a(this.k, this.l);
      this.c.a(this.m);
      this.k = 0;
      this.l = 0;
      this.o = false;
   }

   private void b(zs var1) {
      this.j[this.k] = var1;
      ++this.k;
      this.l += var1.c();
      this.m.a(this.k, this.l);
      this.c.a(this.m);
      this.k = 0;
      this.l = 0;
      this.o = false;
   }

   public void d() {
   }

   public void i(int var1) {
      if (this.a.a) {
         this.a((zs)(new zv(var1)));
      }

   }

   public void j(int var1) {
      if (this.a.a) {
         this.a((zs)(new com.aspose.cells.a.d.a.b.zx(var1)));
      }

   }

   public int a(Shape var1) {
      if (this.o) {
         this.f();
      }

      boolean var2 = zf.a(var1);
      this.c.a(new zci(var2 ? 1 : 2));
      int var3 = this.e.a();
      this.c.a(new com.aspose.cells.a.d.a.a.zm());
      this.i.a(var1, var3);
      this.c.a(new com.aspose.cells.a.d.a.a.zz());
      return var3;
   }

   public int b(Shape var1) {
      int var2 = this.a(var1);
      this.c.a(new zbv(5));
      if (this.a.a) {
         this.a((zs)(new zw(0, var2 - 1)));
      }

      return var2;
   }

   public boolean e() {
      return this.a.a;
   }

   public int a(BasicStroke var1, Color var2, Stroke var3, AffineTransform var4) {
      int var5 = 65536;
      switch(var1.getEndCap()) {
      case 0:
         var5 |= 512;
         break;
      case 1:
         var5 |= 0;
         break;
      case 2:
         var5 |= 256;
      }

      switch(var1.getLineJoin()) {
      case 0:
         var5 |= 8192;
         break;
      case 1:
         var5 |= 0;
         break;
      case 2:
         var5 |= 4096;
      }

      float[] var6 = var1.getDashArray();
      float var7 = this.a((double)var1.getLineWidth());
      if (var7 < 1.0F) {
         var7 = 1.0F;
      }

      zaf var8 = new zaf(var5, var7 < 1.0F ? 1 : (int)var7, var2, var6);
      int var9 = this.e.a();
      this.c.a(new zac(var9, var8));
      if (this.a.a) {
         this.a((zs)(new zp(var9 - 1, new zr(0, var7, var5, var6, var4), new com.aspose.cells.a.d.a.b.zb(var2))));
      }

      this.c.a(new zbw(var9));
      if (var3 != null) {
         if (!(var3 instanceof BasicStroke) || ((BasicStroke)var3).getMiterLimit() != var1.getMiterLimit()) {
            this.c.a(new zcg((int)this.a((double)var1.getMiterLimit())));
         }
      } else {
         this.c.a(new zcg((int)this.a((double)var1.getMiterLimit())));
      }

      return var9;
   }

   public int a(Paint var1) {
      int var2 = this.e.a();
      if (var1 instanceof Color) {
         Color var3 = (Color)var1;
         int var4 = var3.getAlpha() == 0 ? 1 : 0;
         zaq var5 = new zaq(var4, var3, 0);
         if (this.a.a) {
            this.a((zs)(new com.aspose.cells.a.d.a.b.zl(var2 - 1, new com.aspose.cells.a.d.a.b.zb(var3))));
         }

         this.c.a(new com.aspose.cells.a.d.a.a.zr(var2, var5));
      } else if (var1 instanceof TexturePaint) {
         TexturePaint var7 = (TexturePaint)var1;
         this.c.a(new com.aspose.cells.a.d.a.a.zs(var2, var7.getImage()));
      } else if (var1 instanceof GradientPaint) {
         GradientPaint var8 = (GradientPaint)var1;
         Color var9 = var8.getColor1();
         byte var10 = 0;
         zaq var6 = new zaq(var10, var9, 0);
         this.c.a(new com.aspose.cells.a.d.a.a.zr(var2, var6));
      }

      this.c.a(new zbw(var2));
      return var2;
   }

   public int a(Font var1, Map<TextAttribute, ?> var2) {
      zae var3 = new zae(var1, var2);
      int var4 = this.e.a();
      if (this.a.a) {
         this.a((zs)(new com.aspose.cells.a.d.a.b.zm(var4 - 1, var1.getSize2D(), 0, var3.a(), var1.getName())));
      }

      this.c.a(new zab(var4, var3));
      return var4;
   }

   private void g() {
      while(true) {
         int var1 = this.e.b();
         if (var1 < 0) {
            return;
         }

         this.h(var1);
      }
   }

   private float a(double var1) {
      return (float)Math.floor(var1 * 1.0D * 20.0D);
   }
}
